home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / UTIL / Alpha 6.5.sit / Tcl / UserCode / smartModes.tcl < prev    next >
Text File  |  1996-08-15  |  3KB  |  98 lines

  1. ########################################################################
  2. # Emacs-style mode selection using first nonblank line of file
  3. #
  4. # Checks for interpreter line "#!/dir/subdir/command ...", or
  5. # explicit major mode election "-*-Mode: vars ...-*-".
  6. #
  7. # "command" or "Mode" is compared (case-insensitively) to Alpha mode
  8. # names and first matching mode is used for the file.
  9. #
  10. # Author:   Tom Pollard  <pollard@chem.columbia.edu>
  11. # Modified: 9/11/95
  12. #
  13. set emacsMode(rmail) {Mail}
  14. set emacsMode(fortran) {Fort}
  15. set emacsMode(latex) {TeX}
  16. set emacsMode(pascal) {Pasc}
  17. set emacsMode(matlab) {MATL}
  18. set emacsMode(latex) {TeX}
  19.  
  20. proc checkModeLine {name} {
  21.     global modes winModes emacsMode
  22.  
  23.     set modePat {¥-¥*¥- *([^     :;]+).*¥-¥*¥-}
  24.     set intPat {^#!([^     ¥n¥r]+)}
  25.  
  26.     bringToFront $name
  27.     set oldMode winModes($name)
  28.  
  29.     set pos 0
  30.     set line [getText $pos [nextLineStart $pos]]
  31.     while {[regexp {^[     ¥n¥r]*$} $line] && $pos != [maxPos]} {
  32.         set pos [nextLineStart $pos]
  33.         set line [getText $pos [nextLineStart $pos]]
  34.     }
  35.     if {$pos == [maxPos]} { return }
  36.  
  37.     if {[regexp $modePat $line mtch majorMode]} {
  38.     } elseif {[regexp $intPat $line mtch majorMode] } {
  39.         if {![regexp {([^/]+)$} $mtch majorMode]} { return }
  40.     } else {
  41.         return
  42.     }
  43.  
  44.     set majorMode [string tolower $majorMode]
  45. #     set imode [lsearch -exact [array names emacsMode] $majorMode]
  46. #     if {$imode >= 0} { #}
  47.     if {[catch {set winModes($name) $emacsMode($majorMode)}]} {
  48.         foreach m $modes {
  49.             if {[string tolower $m] == $majorMode} {
  50.                 set winModes($name) $m
  51.                 break
  52.             }
  53.         }    
  54.     }
  55.     if {$winModes($name) != $oldMode} { bringToFront $name; centerRedraw }
  56. }
  57.  
  58. # The following replaces the release version of "openHook" in "modes.tcl"
  59. #
  60. proc openHook name {
  61.     global winModes winActive autoMark mode screenHeight screenWidth forceMainScreen recentFiles recentFilesCount
  62.  
  63.     checkModeLine $name
  64.  
  65.     changeMode $winModes($name)
  66.     if {$name == {*Toolserver shell*}} startMPW
  67.     addWinName $name
  68.     message ""
  69.  
  70.     if {![catch {getFileInfo $name info}]} {
  71.         if {$info(creator) == {ttxt}} {
  72.             setWinInfo dirty 0
  73.         }
  74.         if {$info(type) == {ttro}} {
  75.             catch {setWinInfo read-only 1}
  76.             message "Read-only!"
  77.         }
  78.     }
  79.  
  80.     global ${mode}modeVars
  81.     
  82.     if {$forceMainScreen} {
  83.         set geo [getGeometry]
  84.         set l [lindex $geo 0]; set t [lindex $geo 1]; set w [lindex $geo 2]; set h [lindex $geo 3]; 
  85.         if {($l < 0) || ($t < 35) || ([expr $l + $w] > $screenWidth) || ([expr $t + $h + 18] > $screenHeight)} {
  86.             singlePage
  87.         }
  88.     }
  89.     getWinInfo arr
  90.     if {[info exists ${mode}modeVars(autoMark)] && [set ${mode}modeVars(autoMark)] && !$arr(read-only) && ![llength [getNamedMarks -n]]} {
  91.         markFile
  92.     }
  93.     
  94.     if {[string match "*Preferences*defs.tcl" $name]} {setWinInfo read-only 1}
  95.     
  96.     pushRecent $name 
  97. }
  98.